package com.example.baiduai.control;
import com.example.baiduai.tools.FileTools;
import com.example.baiduai.service.OcrService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author wangyizhu
 * @version "1.8.0_131"
 * @email 2641956765@qq.com
 * @desc:
 * @Time 2022/09/23 14:17
 */

public class OcrControl implements Controller {
    public void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //1.设置编码
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        //2获取前端获取的参数
        //如何读取以multipart/form-data形式传递的数据
        String type = req.getParameter("type");
        OcrService ocrService = new OcrService();
        PrintWriter writer = resp.getWriter();
        switch (type) {
            case "currency":
                byte[] data = FileTools.getFileDataByRequest(req);
                String res = ocrService.currency(data);
                writer.write(res);
                break;
            case "animalDetect":
                byte[] d= FileTools.getFileDataByRequest(req);
               String string=ocrService.animalDetect(d);
               writer.write(string);
               break;
            default:
                break;
        }
        writer.flush();
        writer.close();
    }
}
